package com.company.cloud.common.mq.redis.client.consumer;

import java.util.Map;

import org.springframework.util.StringUtils;

import com.alibaba.fastjson.JSON;
import com.company.cloud.common.mq.redis.client.constant.RedisMQConstant;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class MQConsumeMessage {

	private String id;

	private String topic;

	private Map<String, String> data;

	public MQConsumeMessage(String topic,String id, Map<String, String> data) {
			this.topic=topic;
			this.id=id;
			this.data=data;
	}
	
	public String getContent() {
		if(data==null) {
			return null;
		}
		return this.data.get(RedisMQConstant.Msg_Content_Key);
	}
	
	
	public <T> T getContent(Class<T> clazz) {
		String content=this.getContent();
		if(StringUtils.isEmpty(content)) {
			return null;
		}
		return JSON.parseObject(content, clazz);
	}
	

	//RedisMQConstant.Msg_Content_Key
	
	public MQConsumeMessage() {

	}

}
